<template>
  <t-modal
    class="mL"
    :title="title"
    :width="1000"
    :visible="visible"
    :confirmLoading="loading"
    @ok="ok"
    @cancel="() => $emit('cancel')"
  >
    <a-form :form="form">
      <a-spin :spinning="loading">
        <component
          class="nodeForm"
          ref="previewModal"
          :drawing-list="drawingList"
          :is="plugItem"
          v-for="(plugItem, plugIndex) in plugs"
          :key="plugIndex"
          :isview="false"
        ></component>
      </a-spin>
    </a-form>
  </t-modal>
</template>

<script>
export default {
  props: {
    visible: {
      type: Boolean,
      required: true,
    },
  },
  data() {
    return {
      title: "表单",
      form: this.$form.createForm(this),
      loading: false,
      plugs: [],
      saveUrl: "",
      drawingList: null,
    };
  },
  methods: {
    ok() {
      this.loading = true;
      this.form.validateFields((errors, values) => {
        if (!errors) {
          this.$post(this.saveUrl, values)
            .then((res) => {
              if (res.statusCode === 200 || res === 1) {
                this.$emit("ok");
                this.$message.success(res.message || "操作成功", 1.5);
              } else {
                this.$message.success(res.message || "操作失败", 1.5);
              }
            })
            .finally(() => {
              this.loading = false;
            });
        } else {
          this.loading = false;
        }
      });
    },
  },
};
</script>

<style lang="scss" scoped></style>
